home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************************/
- /* ErrorFunction.c */
- /* */
- /* Version 25.9.94 */
- /***************************************************************************************/
-
-
- #include "proFit_interface.h"
- #include <math.h>
-
- #define Inf HUGE_VAL
-
-
-
- /***************************************************************************************/
-
- void SetUp ( short* const moduleKind, /* set moduleKind to isFunction or isProgram */
- Str255 name, /* the name of the program or function (pascal string) */
- long* const requiredGlobals, /* the number of bytes to be allocated in ExtModulesParamBlock.globals */
- /* set requiredGlobals to 0 if you don't use this feature */
- ExtModulesParamBlock* pb) /* the complete parameter block passed by pro Fit to the */
- /* routines defined in this file. In most cases it can be ignored */
- /* SetUp is called once when the external module is linked to proFit */
- {
- *moduleKind=isFunction; /* we define a function */
- SetPascalStr(name,"\pInverse erf",255); /* with the name "Inverse erf" */
- *requiredGlobals=0; /* we define no globals */
- }
-
- /***************************************************************************************/
-
- void InitializeFunc (
- Boolean* const hasDerivatives, /* set this to true if and only if you define the function */
- /* Derivatives to calculate the partial derivatives of the parameters */
- Str255 descr1stLine, /* first line of the text in the parameter window */
- Str255 descr2ndLine, /* second line of the text in the parameter window */
- short* const numberOfParams, /* the number of parameters of the function */
- DefaultParamInfo* const a0, /* the default names, values etc. of the parameters */
- ExtModulesParamBlock* pb) /* the complete parameter block passed by pro Fit to the */
- /* routines defined in this file. In most cases it can be ignored */
- /* InitializeFunc is called once (after SetUp has been called) when the external module is linked to proFit */
- /* Used to set all the information needed to describe a function */
- {
- *hasDerivatives=false;
- SetPascalStr(descr1stLine,"\pThe inverse of the error function.",255);
- SetPascalStr(descr2ndLine,"\py := A*InvErf(x-x0) + const",255);
-
- *numberOfParams=3; /* we have 3 parameters */
-
- /* The following is to set parameter names, fitting modes, etc. */
-
- (*a0->value)[0] = 1.0; /* set their names and defaults */
- (*a0->mode)[0] = inactive;
- SetPascalStr((*a0->name)[0],"\pA", maxParamNameLength);
-
- (*a0->value)[1]= 0.0;
- (*a0->mode)[1] = inactive;
- SetPascalStr((*a0->name)[1],"\px0", maxParamNameLength);
-
- (*a0->value)[2]= 0.0;
- (*a0->mode)[2] = inactive;
- SetPascalStr((*a0->name)[2],"\pconst",maxParamNameLength);
-
- }
-
- /***************************************************************************************/
-
- short Check(short paramNo, /* the parameter that was changed */
- DefaultParamInfo* const a0, /* the default names, values etc of the paramters */
- ExtModulesParamBlock* pb) /* the complete parameter block passed by pro Fit to the */
- /* routines defined in this file. In most cases it can be ignored */
- /* Can be left emtpy (returning good) if not needed. */
- /* called when the user has changed a value in the parameters window. This routine */
- /* can then check if this parameters is fine. It can also change some of the */
- /* other entries in a0. The returned values can be: */
- /* good: return this value if you agree with the new parameter value */
- /* update: return this value if you want the parameters window */
- /* to be updated because you changed some of the values in a0 */
- /* bad: return this value if you want the new parameter value to be refused */
- {
- return good; /* we have nothing to do here */
-
- }
-
- /***************************************************************************************/
-
- void First ( ParamArray a, /* the new parameters */
- ExtModulesParamBlock* pb) /* the complete parameter block passed by pro Fit to the */
- /* routines defined in this file. In most cases it can be ignored */
- /* Can be left emtpy if not needed. */
- /* Called whenever the parameters are changed. Can be used to accelerate */
- /* some calculations. See manual for more info */
- {
- }
- /***************************************************************************************/
-
-
- static double InvErf(double x)
- // returns the inverse of the error function
- // accuracy better than 1e-7
- // this function was inspired by A.J. Strecok, math. comp. 1968, page 144ff
- // accuracy between -0.999 and 0.999: better than 10E-7
- // (C) 1996 QuantumSoft
- {
- double y;
-
- y = sqrt(-log(1.0-x*x));
-
- y = y * (0.6374868939151371 + y*(-0.2767067324742911 + y*
- (0.1503581502062744 + y * (-2.5878691411691874e-2 + y * 9.7670209741420530e-3)))) /
- (0.7193322618853618 + y*(-0.3122885268724753 + y*
- (0.1614016565020622 + y * (-2.5947254488147567e-2 + y * 9.7832443176615724e-3))));
-
- if (x<0) y *= -1;
- return y;
- }
-
- void Func ( double x, /* the x-value */
- ParamArray a, /* the parameters */
- double* const y, /* the y-value to be returned */
- ExtModulesParamBlock* pb) /* the complete parameter block passed by pro Fit to the */
- /* routines defined in this file. In most cases it can be ignored */
- /* called to calculate the y-value of the function for a given x and a given */
- /* set of parameters */
- {
- *y = a[0]*InvErf(x-a[1]) + a[2];
- }
-
- /***************************************************************************************/
-
- void Derivatives(double x, /* the x-value */
- ParamArray a, /* the parameters */
- ParamArray dyda, /* the derivatives to be returned */
- ExtModulesParamBlock* pb) /* the complete parameter block passed by pro Fit to the */
- /* routines defined in this file. In most cases it can be ignored */
- /* Can be left empty if InitializeFunc sets hasDerivatives to false */
- /* called to calculate the partial derivatives of the function with respect to */
- /* its parameters. If you leave this function empty and set hasDerivatives to false in */
- /* FuncInitialize, the derivatives will be calcuated numerically, otherwise pro Fit */
- /* calls this function to obtain the values of ALL derivatives. */
- /* As a result of the numerical calculation fitting will be slower */
- {
- }
-
-
-
- /***************************************************************************************/
-
- void Last (ExtModulesParamBlock* pb)
- /* Can be left emtpy if not needed. */
- /* Called when calculating is through. See manual for more info */
- {
- }
-
- /***************************************************************************************/
-
- void CleanUp (ExtModulesParamBlock* pb)
- /* called when the external module is removed from pro Fit's menus */
- /* in most cases, this function can be empty */
- {
- }
-
-
-
-
-
- /***************************************************************************************/
- /* for programs, not used here: */
- /***************************************************************************************/
-
- void InitializeProg (ExtModulesParamBlock* pb)
- {}
-
- void Run(ExtModulesParamBlock* pb)
- {}
-
-
-